<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html style="height:100%">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>左侧菜单树</title>
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<!--  树结构  -->
<script type="text/javascript" src="${_resources}js/jquery.ztree.core.js"></script>
<link rel="stylesheet" href="${_resources}css/zTreeStyle.css" type="text/css">
<link href='${_resources}css/style.css' type='text/css' rel='stylesheet' />
<script type="text/javascript">

 	var	parentId;
	var ztree;
	var setting = {	
			view: {
				fontCss : {border:"0",background:"none","text-decoration":"none"},
                showIcon: false,
    			showLine: true,
    			selectedMulti: false,
    			dblClickExpand: false
    		},
		data: {
			simpleData: {
				enable: true,
				idKey: "menuId",
				pIdKey: "parentId"
			}
		},
		callback: {
			onNodeCreated: this.onNodeCreated,				
			onClick:onClick			
		}
	};
	
	var zNodes = eval('(${menuList})');
	
	var myWork = "";
	$(document).ready(function(){
		myWork = "1";
		ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
		ztree.expandNode(ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//展开指定节点
		ztree.setting.callback.onClick(null, ztree.setting.treeId, ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//触发函数
		loadTree("${needExpandNodeId}");
		$("#menuName").click(function(){
			if(this.innerText.indexOf("组织资产") != -1){
				ztree.expandNode(ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//展开指定节点
				var div = document.getElementById("templatelist");
				div.src ="${_baseUrl}/organizeassetsKTController/showOrganizeassetsIndex?parentMenuId=${menuInfo.menuId}";				
			}			
		});
	});
	function loadTree(nodeId){
		myWork = "1";
		ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
		ztree.selectNode(ztree.getNodeByParam("menuId",nodeId,null));//选中指定节点
		ztree.setting.callback.onClick(null, ztree.setting.treeId, ztree.getNodeByParam("menuId",nodeId,null));//触发函数
	}
	
	function onClick(e,treeId, treeNode) {
		var projectId = "${projectId}";
		if(myWork != '1'){
			projectId = "";
		}
		myWork ="";
		parentId=treeNode.menuId;
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.expandNode(treeNode);
        var div = document.getElementById("templatelist");
        var customer = getCustomer(treeNode);
        var menuName = treeNode.name;
        if("文档模板管理" == menuName ){ //17所标识 点击文档模板管理 跳转到组织级文档模板即可
			if("siyuan17suo" == customer){
				parentId="94c1244aebb7427497521e96a48f330c";
				ztree.selectNode(ztree.getNodeByParam("menuId",parentId,null));//选中指定节点
				div.src ="${_baseUrl}/KmGroupDocumentTemplateController/showGroupDocumentTemplate?menuId="+treeNode.menuId+"&id=${id}&projectstatus=${projectstatus}&nodeId=${id}&projectId="+projectId;
			}else {
				div.src ="${_baseUrl}"+treeNode.menuUrl+"?menuId="+treeNode.menuId+"&id=${id}&projectstatus=${projectstatus}&nodeId=${id}&projectId="+projectId;
			}
		}else{
			div.src ="${_baseUrl}"+treeNode.menuUrl+"?menuId="+treeNode.menuId+"&id=${id}&projectstatus=${projectstatus}&nodeId=${id}&projectId="+projectId;
		}

		<%--div.src ="${_baseUrl}"+treeNode.menuUrl+"?menuId="+treeNode.menuId+"&id=${id}&projectstatus=${projectstatus}&nodeId=${id}&projectId="+projectId;--%>
	}

	//获取标识;17所标识下，点击组织资产管理，跳转到组织级文档模板列表,点击文档模板管理，左侧树选中组织级文档模板
	function getCustomer(treeNode) {
		var customer = "";
		var menuName = treeNode.name;
		if("文档模板管理" == menuName ){
			var path="${_baseUrl}/KmGroupDocumentTemplateController/getCustomer";
			$.ajax({
				type: "POST",
				async: false,
				url:path,
				data:{},
				dataType:"json",
				success: function (data) {
					customer = data.data;
				}
			});
		}
		return customer;
	}
	
	function skip(url,menuId){
		var div = document.getElementById("templatelist");
		if(url.indexOf("showTestProcessDemandMenu") != -1){
			var projectId = url.substring(url.indexOf("=")+1,url.indexOf("&"));
			parent.skipModule1("测试管理","${_baseUrl}/jurisdiction/menuList",'',"d42f113426d7436ba1683856cc1697a1",projectId);
		}else{
			if(url.indexOf("?") > 0){
				div.src ="${_baseUrl}"+url+"&menuId="+menuId;
			}else{
				div.src ="${_baseUrl}"+url+"?menuId="+menuId;
			}
		}
	}
	
	
	function skipModule(menuName,url,menuId){
		ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
		ztree.selectNode(ztree.getNodeByParam("menuId",menuId,null));//选中指定节点
		if(url != null && url != ""){
			var div = document.getElementById("templatelist");
			div.src = url;
		}
	} 
	
	function refreshTree(){
		 var menuId="${menuInfo.menuId}"; 
		 $.ajax({
				url : "${_baseUrl}/jurisdiction/menuTreeList?menuId="+menuId,
				type : "post",
				dataType : "json",
				async : false,//** ！重要 同步请求。效果:ajax未进行则其他代码不运行
				success : function(json) {
					if(json.code=="1"){
						zNodes= eval(json.data);
						ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
						ztree.selectNode(ztree.getNodeByParam("menuId",parentId,null));//选中指定节点
						ztree.expandNode(ztree.getNodeByParam("menuId",parentId,null));//展开指定节点	
						$("#menuName").click(function(){
							if(this.innerText.indexOf("组织资产") != -1){
								ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
								ztree.expandNode(ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//展开指定节点
								var div = document.getElementById("templatelist");
								div.src ="${_baseUrl}/organizeassets/showOrganizeassetsIndex";				
							}			
						});
					}	
				},
				error:function(data){
					layer.msg("系统错误,请联系管理员");
				}
			});
	}
	function gotoProjectBaseInfo(projectId,projectStatus){
		//parent.location.href="${_baseUrl}/projectKt/showProjectBaseinfo?projectId="+projectId;
		var path = "${_baseUrl}/projectKt/showProjectBaseinfo?projectId="+projectId+"&sonPage=yes";
		if(projectStatus == '1'){
			layerIndex =layer.open({
				 type: 2,
				 title:'设置项目详细信息',
				 area: ['900px', '400px'],
				 fixed: false, //不固定
				 maxmin: true,
				 shim: true,
				 content: path,
				 success: function(){
					
				 },
				 moveEnd: function(layero){
					 
				 },
				 cancel: function(){ 
					 layer.closeAll();
				}
			});
			layer.full(layerIndex);
		}else if(projectStatus == undefined){
			path = "${_baseUrl}/projectKt/showProjectBaseinfo?projectId="+projectId+"&sonPage=yes&build=yes";
			layerIndex =layer.open({
				 type: 2,
				 title:'设置项目详细信息',
				 area: ['900px', '400px'],
				 fixed: false, //不固定
				 maxmin: true,
				 shim: true,
				 content: path,
				 success: function(){
					
				 },
				 moveEnd: function(layero){
					 
				 },
				 cancel: function(){ 
					 layer.closeAll();
				}
			});
			layer.full(layerIndex);
		}else{
			layerIndex = layer.open({
				 type: 2,
				 title:'修改项目详细信息',
				 area: ['900px', '400px'],
				 fixed: false, //不固定
				 maxmin: true,
				 shim: true,
				 content: path,
				 success: function(){
					
				 },
				 moveEnd: function(layero){
					 
				 },
				 cancel: function(){ 
					 layer.closeAll();
				}
			});
			layer.full(layerIndex);
		}
	}
	
	function gotoProjectBaseInfoView(projectId){
		var path = "${_baseUrl}/projectView/showProjectBaseinfoView?projectId="+projectId;
		layerIndex = layer.open({
			 type: 2,
			 title:'项目详细信息',
			 area: ['900px', '400px'],
			 fixed: false, //不固定
			 maxmin: true,
			 shim: true,
			 content: path,
			 success: function(){
				
			 },
			 moveEnd: function(layero){
				 
			 },
			 cancel: function(){ 
				 layer.closeAll();
			}
		});
		layer.full(layerIndex);
	}
	
	/* 关闭弹出框 */
	function closeWin(){
		layer.closeAll();
	}
	
	function defineTemplateSort(){	
		layer.open({
		  type: 2, 
		  title:'类别管理',
		  area: ['500px', '370px'],
		  shade: 0.3, //遮罩透明度
		  fixed: false, //不固定
		  maxmin: true,
		  shim: true,
		  content: '${_baseUrl}/OMenuDescribe/showOrganizeassetsMenuTree?menuId=${parentMenuId}',
		  cancel: function(index, layero){ 
			    layer.close(index)
			    window.location.reload(true);
			}    
		});
	}
	   /* 重新出发一次最后点击的节点 */
    function onclickLastMenu(){
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.setting.callback.onClick(null, zTree.setting.treeId, zTree.getNodeByParam("nodeId",lastOnClickNodeId,null));//触发函数
    }
</script>
<style type="text/css">
.main_left .ztree li a{color:#666;height:25px;line-height:25px}
#treeDemo{overflow-x: auto;}
.main_left .ztree li a .node_name{ display: inline-block;max-width:75px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
.main_left .ztree li.level0 a .node_name{max-width: 134px;}
.main_left .ztree li.level1 a .node_name{max-width: 118px;}
.main_left .ztree li.level2 a .node_name{max-width: 101px;}
.main_left .ztree li.level3 a .node_name{max-width: 83px;}
.main_left .ztree li.level4 a .node_name{max-width: 10px;}
#box{width:100%;height:100%;overflow:hidden;}
#main-left{width:-moz-calc(15% - 5px);width:-webkit-calc(15% - 5px);width:calc(15% - 5px);height:100%;float:left;}
#btn1{width:5px;height:100%;cursor: w-resize;float:left;background: #ccc;}
#main-right{float:right;width:85%;height:100%;}
.ztree li a.curSelectedNode{padding:0px 3px 0 0;}
.ztree li a{padding: 0px 3px 0 0;} 
.ztree li span.button.switch{height: 22px;}
</style>

</head>
<body style="height:100%">

<div id="box" class="main">
    <div id="main-left" class="zTreeDemoBackground">
       	<c:if test="${menuInfo.menuId == '11111' or menuInfo.menuId == '22222'}">
        	<div style="margin-top:9px">
		       <a class="aaaaa" href="${_baseUrl}/organizeassetsKTController/showOrganizeassetsIndex?parentMenuId=${menuInfo.menuId}" target='aaaaaaa' style="font-size: 14px;color:#666;margin-left:15px">全部资产</a>
		       <c:if test="${menuInfo.menuId == '22222'}">
		       		<a onclick="defineTemplateSort();" id="newTestRequirements" href="javascript:;" style="float:right;background-color: #fff;color: #3979FF;font-size: 14px;padding:0px 8px 4px;">类别管理</a>
		       </c:if>	
		    </div>
        	<c:if test="${numberCode eq 'tianjin712suo'}">
				<div style="margin-top:19px">
		        	<a class="aaaaa" href="${_baseUrl}/organizeassetsKTController/showOrganizeassetsIndex?parentMenuId=${menuInfo.menuId}" target='aaaaaaa' style="font-size: 14px;color:#666;margin-left:15px">全部资产</a>
		        </div>	        		
		    </c:if>	
		    <ul id="treeDemo" class="ztree"></ul>
        </c:if>
        <c:if test="${menuInfo.menuId != '11111' and menuInfo.menuId != '22222'}">
        	<ul id="treeDemo" class="ztree"></ul>
        </c:if>
    </div> 
    <div id="btn1"></div> 
	<div id="main-right">
		<iframe id=templatelist name="ziyemian" frameborder="0" style="width:100%; height:100%;" src=""></iframe>   
	</div> 
</div>
</body>
<script type="text/javascript">
var  resizeTimer = null;
window.onload = function(){
	initHeight();
	huadong();
}
window.onresize = function(){
    if(resizeTimer) clearTimeout(resizeTimer);
    resizeTimer = setTimeout("initHeight();huadong()",100);
 }
	function initHeight(){
		/* var oMaBox = document.getElementById("menu"); */
		var topH = 0; // oMaBox.getBoundingClientRect().height;  
		
		if(navigator.userAgent.indexOf("MSIE")>0 || navigator.userAgent.indexOf("like Gecko")>0) {//IE浏览器
			//topH = oMaBox.clientHeight; 
			initheight = document.documentElement.clientHeight-topH;
		}
		if(navigator.userAgent.indexOf("Firefox")>0){//Firefox浏览器
			initheight = document.documentElement.clientHeight-topH;
		}
		if(navigator.userAgent.indexOf("Opera")>0){//Opera浏览器
			initheight = document.body.clientHeight-topH;
		}
		if(navigator.userAgent.indexOf("Chrome")>0){//Chrome谷歌浏览器
			initheight = document.documentElement.clientHeight-topH;
		}
		if(navigator.userAgent.indexOf("Safari")>0){//Safari浏览器
			initheight = document.documentElement.clientHeight-topH;
		}
		$("#treeDemo").css("height",initheight );
		$("#btn1").css("height",initheight );
		$("#main-right").css("height",initheight);
		
	}
	function huadong(){
		var resize = document.getElementById("btn1");
        var left = document.getElementById("main-left");
        var right = document.getElementById("main-right");
        var box = document.getElementById("box");
        var childWindow = $("#templatelist")[0].contentWindow;
        resize.onmousedown = function(e){
            var startX = e.clientX;
            resize.left = resize.offsetLeft;
            document.onmousemove = function(e){
                var endX = e.clientX;
                var moveLen = resize.left + (endX - startX);
                var maxT = box.clientWidth - resize.offsetWidth;
                if(moveLen<150) moveLen = 150;
                if(moveLen>maxT-150) moveLen = maxT-150;

                resize.style.left = moveLen;
                left.style.width = moveLen + "px";
                right.style.width = (box.clientWidth - moveLen - 5-12) + "px";
            }
            document.onmouseup = function(evt){
                document.onmousemove = null;
                document.onmouseup = null;
                resize.releaseCapture && resize.releaseCapture();
            }
            resize.setCapture && resize.setCapture();
            return false;
        }
	}
</script>
</html>